#include "Decrypter.h"

Decrypter::Decrypter(const char* keyName)
{
  // read in pem-encoded encrypted private key
	BIO* rsaPrivateBio2 = BIO_new_file(keyName, "r");
	rsaPriv = RSA_new();
	PEM_read_bio_RSAPrivateKey(rsaPrivateBio2, &rsaPriv, NULL, NULL);
	BIO_free(rsaPrivateBio2);
}

Decrypter::~Decrypter()
{
	RSA_free(rsaPriv);
}

char* Decrypter::DecryptData(const char* inBuf, int len)
{
 	// decrypt
	unsigned char* decrypt_buf = new unsigned char[len];
	memset((void*) decrypt_buf, 0, len);

	RSA_private_decrypt(len, (unsigned char*) inBuf, decrypt_buf, rsaPriv, PADDING);

  return ((char*)decrypt_buf);
}
